package com.example.demo.graph;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OpenAITestController {

    private final ChatClient chatClient;

    public OpenAITestController(ChatClient.Builder builder) {
        this.chatClient = builder.build();
    }

    @GetMapping("/test-openai")
    public String test(@RequestParam(defaultValue = "你好，你是谁？") String prompt) {
        return chatClient.prompt()
                .user(prompt)
                .call()
                .content();
    }
}